package com.mvc.moduel1.testproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class BusinessProxy implements InvocationHandler{
	private Object obj;
	BusinessProxy(){
		
	}
	BusinessProxy(Object obj){
		this.obj = obj;
	}
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		Object result = null;
		doBefore();
		result = method.invoke(obj, args);
		doAfter();
		return result;
	}
	public void doBefore(){
		System.out.println("do something before Business Logic");
	}
	public void doAfter(){
		System.out.println("do something after Business Logic");
	}
	
	public static Object factory(Object object){
		Class clazz = object.getClass();
		return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), new BusinessProxy(object));
	}

}
